package com.ruoyi.kenuo.controller;

import java.io.OutputStream;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kenuo.domain.KernelVersionValue;
import com.ruoyi.kenuo.service.IKernelVersionValueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author polo tang
 * @date 2023-06-12
 */
@RestController
@RequestMapping("/kenuo/value")
public class KernelVersionValueController extends BaseController
{
    @Autowired
    private IKernelVersionValueService kernelVersionValueService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('kenuo:value:list')")
    @GetMapping("/list")
    public TableDataInfo list(KernelVersionValue kernelVersionValue)
    {
        startPage();
        List<KernelVersionValue> list = kernelVersionValueService.selectKernelVersionValueList(kernelVersionValue);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('kenuo:value:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KernelVersionValue kernelVersionValue)
    {
        List<KernelVersionValue> list = kernelVersionValueService.selectKernelVersionValueList(kernelVersionValue);
        ExcelUtil<KernelVersionValue> util = new ExcelUtil<KernelVersionValue>(KernelVersionValue.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('kenuo:value:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(kernelVersionValueService.selectKernelVersionValueById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('kenuo:value:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KernelVersionValue kernelVersionValue)
    {
        return toAjax(kernelVersionValueService.insertKernelVersionValue(kernelVersionValue));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('kenuo:value:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KernelVersionValue kernelVersionValue)
    {
        return toAjax(kernelVersionValueService.updateKernelVersionValue(kernelVersionValue));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('kenuo:value:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(kernelVersionValueService.deleteKernelVersionValueByIds(ids));
    }

    @PostMapping("/getVersionList")
    public AjaxResult getVersionList(@RequestBody KernelVersionValue kernelVersionValue) {
        //底座sn
        AjaxResult aj = new AjaxResult();
        //查询版本号
        List<String> str = kernelVersionValueService.selectHao();
        if(str.size()>0){
            String strver = str.get(0);
            kernelVersionValue.setRemarkOne(strver);
            List<KernelVersionValue> list = kernelVersionValueService.selectKernelVersionValueList(kernelVersionValue);
            aj.put("code", 200);
            aj.put("msg", "success");
            aj.put("version", strver);
            aj.put("data", list);
        }
        return aj;
    }
}
